import { defineStore } from 'pinia';
// import type { AppState } from "./types";

export const useStoreSystem = defineStore("system", {
    state: () => {
        return {
            loading: false, // 加载状态
            statusBarHeight: 0, // 手机状态栏高度:
            isIosVal: null, // 手机状态栏高度:
            tabbarHeight: 0, // 底部栏高度
            safeAreaInsetsBottom: 0,
            wxMenuBut: {
                bottom: 0,
                left: 0,
                right: 0,
                top: 0,
                width: 0,
                height: 0,
                // #ifndef MP
                placeholder: 0,
                // #endif
                // #ifdef MP
                placeholder: 97,
                // #endif
            }, // 微信小程序胶囊按钮信息(占位符wxMenuBut.placeholder该值为胶囊最左边距离屏幕最右边缘的距离，单位：px):


            systemInfo: {}
        };
    },
    actions: {
        setLoading(loading) {
            this.loading = loading;
        },
        getSystemInfo() {
            // #ifdef MP
            let menuButton = {
                bottom: 58,
                left: 278,
                right: 365,
                top: 26,
                width: 87,
                height: 30,
                placeholder: 97,
            };
            let that = this;
            uni.getSystemInfo({
                success: (res) => {
                    let menuButtonBounding = uni.getMenuButtonBoundingClientRect();
                    let menuButton = {
                        bottom: menuButtonBounding.bottom,
                        left: menuButtonBounding.left,
                        right: menuButtonBounding.right,
                        top: menuButtonBounding.top,
                        width: menuButtonBounding.width,
                        height: menuButtonBounding.height,
                        placeholder: res.windowWidth - menuButtonBounding.left, //点位符
                    };
                    console.log('menuButton--',menuButton);
                    that.systemInfo = res
                    that.setWxMenuBut(menuButton);
                    that.setStausBarHeight(res.statusBarHeight);
                    console.log("res.safeAreaInsets.bottom", res.screenHeight);

                    that.safeAreaInsetsBottom = res.safeAreaInsets.bottom;
                    const { screenHeight, windowHeight, statusBarHeight, pixelRatio } =
                        res;
                    that.tabbarHeight = screenHeight - windowHeight;
                    that.isIosVal = res.model.includes("iPhone");
                    // console.log('that', tabbarHeight);
                },
            });

            // #endif
        },
        setStausBarHeight(statusBarHeight) {
            console.log('statusBarHeight--', statusBarHeight);
            this.statusBarHeight = statusBarHeight;
            // console.log(statusBarHeight,'statusBarHeight')
        },
        setWxMenuBut(wxMenuBut) {
            this.wxMenuBut = wxMenuBut || {};
            // console.log(wxMenuBut,'wxMenuBut')
        },
        setInfoData(data = {}) {
            for (let key in data) {
                this[key] = data[key];
            }
        },


    },
    getters: {

    },
    persist: {},
});

export default useStoreSystem;
